﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodsHealShowCommandHandler : IRequestHandler<GoodsHealShowCommand, APIResult<List<GoodshealthInfo>>>
    {
        private readonly IBaseRepository<GoodshealthInfo> _goodshealrepository;
        public GoodsHealShowCommandHandler(IBaseRepository<GoodshealthInfo> goodshealrepository )
        {
            _goodshealrepository = goodshealrepository;
        }
        public Task<APIResult<List<GoodshealthInfo>>> Handle(GoodsHealShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<GoodshealthInfo>> result = new APIResult<List<GoodshealthInfo>>();
            try
            {
                var list = _goodshealrepository.GetAll().Where(x => x.GoodsId == request.Id&&x.IsDeleted==false).ToList();
                result.Code = ApiEnum.Success;
                result.Msg = "保健信息显示成功";
                result.Data = list;
                return Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Code = ApiEnum.Fail;
                result.Msg = "保健信息显示失败";
                return Task.FromResult(result);
                throw;
            }
        }
    }
}
